package com.channelsharing.cloud.tencent.cos;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.region.Region;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author : cookie ✌️
 * @date : 2019/3/27 20:02
 */
@Configuration
public class TencentCosConfig {
    @Autowired
    private TencentCos tencentCos;

    /**
     * 生成cos客户端
     *
     * @return COSClient
     */
    @Bean
    public COSClient cOSClient() {
        BasicCOSCredentials credentials = new BasicCOSCredentials(tencentCos.getSecretId(), tencentCos.getSecretKey());
        // 2 设置bucket的区域, COS地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
        // clientConfig中包含了设置region, https(默认http), 超时, 代理等set方法, 使用可参见源码或者接口文档FAQ中说明
        ClientConfig clientConfig = new ClientConfig(new Region("ap-chengdu"));
        return new COSClient(credentials, clientConfig);
    }
}
